package com.wangwei.modules.container

import javax.servlet.Servlet
import javax.servlet.ServletConfig

/**
 *servlet工厂
 */
object ServletFactory {


	//普通servlet的调用:path obj
	var servletMap = hashMapOf<String, Servlet>();

	//根据路径获取方法
	fun getNormalMethodByPath(path: String): Servlet? {

		for ((p, s) in servletMap) {
			if (path.equals(p)) {
				return s
			}
		}


		for ((p, s) in servletMap) {
			if (path.matches(Regex(p))) {
				return s
			}
		}
		return null
	}


	fun addWebServlet(path: String, className: String) {

		var config: ServletConfig? = null
		var any = Class.forName(className).newInstance()
		if (any is Servlet) {
			any._init(config)
			servletMap.put(path, any)
		}

	}


}